# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_variant=-static
#_variant=-shared
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "kcwsh"
_ver_base=0.1.0
pkgbase=mingw-w64-kcwsh-qt5-git
pkgver=0.1.0.236.be0e645
pkgrel=1
arch=('any')
url='https://projects.kde.org/projects/frameworks/${_basename}'
pkgdesc="Plugins to allow QImage to support extra file formats (mingw-w64-qt5${_namesuff})"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
             "git")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}" "${MINGW_PACKAGE_PREFIX}-bzip2"
groups=('kf5')
source=("${_realname}"::"git+https://anongit.kde.org/${_basename}.git"
        "0001-Add-std-c-11-globally.patch"
        "0002-qt-frontend-Set-AUTOSTATICPLUGINS-don-t-force-lib-kc.patch"
        "0003-build-both-static-and-shared-kcwsh-libraries.patch")
sha256sums=('SKIP'
            '8d34b0c0d129c64877fc1c64ff9875f6b6dedecbf7fbc664c61255a09ce6a987'
            '0023036cce30018cf90d69b839a81beb06d378766e9fba64ffc0ebf6eb481166'
            'a4b9afe82d6a63bd26bd0bcee3eccd259e6f9801d2b1ea809e130313d8475660')

pkgver() {
  cd "${srcdir}"/${_realname}
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd "${srcdir}"/${_realname}
  git am "${srcdir}"/0001-Add-std-c-11-globally.patch
  git am "${srcdir}"/0002-qt-frontend-Set-AUTOSTATICPLUGINS-don-t-force-lib-kc.patch
  git am "${srcdir}"/0003-build-both-static-and-shared-kcwsh-libraries.patch
}

build() {
  local -a extra_config
  mkdir -p build-${CARCH}${_variant}
  cd build-${CARCH}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
    QT5_PREFIX=${MINGW_PREFIX}/qt5-static
    export PATH=${QT5_PREFIX}/bin:"$PATH"
  else
    QT5_PREFIX=${MINGW_PREFIX}
  fi

  MSYS2_ARG_CONV_EXCL=-DCMAKE_INSTALL_PREFIX \
  cmake ../${_realname} \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${QT5_PREFIX} \
    -DLIB_INSTALL_DIR=lib \
    -DECM_MKSPECS_INSTALL_DIR=${QT5_PREFIX} \
    -DQt5_DIR=${QT5_PREFIX}/lib/cmake/Qt5 \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    "${extra_config[@]}" \
    -G'MSYS Makefiles'
  make VERBOSE=1
}

package() {
  cd build-${CARCH}${_variant}
  make DESTDIR="${pkgdir}" install
}
